package com.excilys.capicsoubank.webservices.rest.impl;

import javax.ws.rs.core.Response;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.excilys.capicsoubank.dto.Transfer;
import com.excilys.capicsoubank.exception.NegativeBalanceException;
import com.excilys.capicsoubank.services.TransactionService;
import com.excilys.capicsoubank.webservices.rest.TransferWebService;

@Component("transferWebServiceImpl")
public class TransferWebServiceImpl implements TransferWebService {

	@Autowired
	private TransactionService transactionService;

	@Override
	public Response transferJson(Transfer transfer)
			throws NegativeBalanceException {

		transactionService.transferBetweenAccounts(
				transfer.getAccountSourceId(),
				transfer.getAccountDestinationId(), transfer.getAmount());

		return Response.ok().build();
	}
}
